
$(document).ready(function() {
	
	var siteFBPrice = 1.00;
	try {
		siteFBPrice = $.parseJSON($.cookie('User')).siteFBPrice;
	} catch(e) {
		console.log(e);
	}
	
	$("#buy-fb-num").keyup(function(e) {
        var fbnum = $.trim($("#buy-fb-num").val());
		var numReg = /^[1-9][0-9]{0,3}$/;
		if(numReg.test(fbnum)) {
			var fbMoney = Utils.formatMoney(siteFBPrice * fbnum);
			$(".fb-sum-m").text("（共需"+ fbMoney +"元）");
		}
    });
	
	/* 购买飞币 */
	$(".buy-fb-bt").click(function(e) {
		var money = 0;	//账户余额
		try {
			money = $.parseJSON($.cookie('User')).money;
		} catch(e) {
			console.log(e);
		}
		var fbnum = $.trim($("#buy-fb-num").val());
		var numReg = /^[1-9][0-9]{0,3}$/;
		if(!numReg.test(fbnum)) {
			Utils.msgDialog("请输入正确的飞币数量！");
			return;
		}
		var param = {
			feibi: fbnum,
		};
        AQ.callAQ("buyFeibi.do", param, function(result) {
			Utils.msgDialog(result[0].info);
			Utils.refreshUserInfo();	//刷新用户信息
			$("#buy-fb-num").val("");
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
	/* 批量购买飞币 */
	$(".fb-pl-bt").click(function(e) {
		var fbnum = $("#pl-fb-num").val();
		var param = {
			feibi: fbnum,
		};
        AQ.callAQ("buyFeibiPL.do", param, function(result) {
			Utils.msgDialog("购买成功");
			Utils.refreshUserInfo();	//刷新用户信息
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
	/* 合作购买飞币 */
	$(".fb-hz-bt").click(function(e) {
		var fbnum = $("#hz-fb-num").val();
		var param = {
			feibi: fbnum,
		};
        AQ.callAQ("buyFeibiHZ.do", param, function(result) {
			Utils.msgDialog("购买成功");
			Utils.refreshUserInfo();	//刷新用户信息
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
	/* 升级VIP */
	$(".buy-vip-bt").click(function(e) {
		var month = $(".sel-vip").val();
		var param = {
			month: month,
		};
        AQ.callAQ("buyVIP.do", param, function(result) {
			Utils.msgDialog("成功升级VIP！");
			Utils.refreshUserInfo();	//刷新用户信息
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
});